package com.flirc
{
	public class User
	{
		public var nick: String;
		public var ident: String;
		public var host: String;
		
		private var mail:String;
		private var altnick:String;
		private var description:String;
		private var pass:String;
		
		public function User()
		{
			nick = ident = host = '';
		}
		
		public function getMask(): String
		{
			return (nick + '!' + ident + '@' + host);
		}
		
		public function getDescription():String {
			return description;
		}
		
		public function setDescription(description:String ):void {
			this.description = description;
		}
		
		public function getMail():String {
			return mail;
		}
		
		public function setMail(mail:String):void {
			this.mail = mail;
		}
		
		public function getNick():String {
			return nick;
		}

		public function setPass(pass:String):void {
			this.pass = pass;
		}
		
		public function  getPass():String {
			return pass;
		}
		
		public function setNick(nick:String ):void {
			this.nick = nick;
		}
		
		public function getAltnick():String {
			return altnick;
		}
		
		public function get realnick():String
		{
			if (nick.substr(0, 1) in '@~+%') return nick.substr(1);
			else return nick;
		}
		
		public function setAltnick(altnick:String):void {
			this.altnick = altnick;
		}
		
		static public function getUserFromAddress( address: String ): User {
			var user: User = new User();
			var exp: Array = address.match( /(.+?)\!(.+?)\@(.+)/ );
			
			if ( exp == null )
			{
				user.nick = address;
				user.ident = user.host = '';
			}
			else
			{
				user.nick  = exp[ 1 ];
				user.ident = exp[ 2 ];
				user.host  = exp[ 3 ];
			}
			
			return user;
		}		
	}
}